// pages/Reasoning/ReasonIndex/ResonIndex.js
var Data=require("../../../Data/reson.js")
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //userDoList: new Array,
    // isStarted:false,
    // showResult:true,   
    gradetext: '成绩：',
    reasongrade: 0,//成绩
    questionnum: 5,//总数
    questions: Data.questions,//题库
    index: 0,//下标
    canAnswer: '',//是否可以答题
    currentId:''
  },

  onItemClick:function(e){
    //获取当前选中的id
    var select = e.currentTarget.id;
    console.log('Clicked view with id:', e.currentTarget.id);
    var correctAnswer = Data.questions[this.data.index].correctAnswer;
    Data.questions[this.data.index].userAnswer=select// 更新选中选项

    this.setData({
      currentId: select, // 更新currentId的值
    });


    if(select == correctAnswer){
      this.setData({
        reasongrade: this.data.reasongrade + Data.questions[this.data.index].flag,//得分
        //userDoList
      })
      app.globalData.reasongrade = this.data.reasongrade;
      console.log(app.globalData.reasongrade)
    }
    if (this.data.index < this.data.questionnum - 1){
      setTimeout(() => {
        this.NextQuestion(); // 延时执行的代码
      }, 500);
   
      
    }
    //最后一道题
    else if (this.data.index == this.data.questionnum - 1){
      this.setData({
        canAnswer:'true'//禁止答题
      })
      this.GoEnd();
    }
  },
  //跳转下一道题
NextQuestion: function(){
	//不是最后一道题
	if (this.data.index < this.data.questionnum - 1){
		this.setData({
			index: this.data.index + 1,
		})
	}
	//最后一道题
	if (this.data.index == this.data.questionnum - 1) {
		this.setData({
			index: this.data.index,
		})
	}
},
//跳转结束页面
GoEnd:function(){
	wx.navigateTo({
		url: '/pages/Reasoning/resonEnd/resonEnd',
	})
}
  })